﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

using EzDesk.DesktopClient.ServiceLocator.ClientService;
using EzDesk.DesktopClient.Model;
using EzDesk.DesktopClient.Event;
using EzDesk.EventAggregation;
using EzDesk.Generic;

using EzDesk.DesktopClient.ServiceLocator;

namespace EzDesk.DesktopClient
{
    public class AppManagement : ManagementBase<AppManagement>
    {
        private ObservableCollection<App> _appCollection;

        public ObservableCollection<App> AppCollection
        {
            get
            {
                if (_appCollection == null)
                {
                    _appCollection = new ObservableCollection<App>(this.ClientService.GetCurrentApps());
                }
                return _appCollection;
            }
        }

        private ObservableCollection<AppTask> _taskCollection;

        public ObservableCollection<AppTask> TaskCollection
        {
            get
            {
                if (_taskCollection == null)
                {
                    _taskCollection = new ObservableCollection<AppTask>(this.ClientService.GetAllAppTasks(this.CurrentUser.Id, ServiceConfigurationManagement.Instance.ClientType));
                }
                return _taskCollection;
            }
        }

        public AppManagement()
            : base()
        {

        }
    }
    public static class AppExt
    {
        public static IEnumerable<AppTask> GetTasks(this App source)
        {
            return AppManagement.Instance.TaskCollection.Where(t => t.AppName == source.Name);
        }
    }
}
